package org.foreningsgatan.genetics.grid;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.foreningsgatan.genetics.Program;
import org.foreningsgatan.genetics.SimulationEnvironment;
import org.gridgain.grid.GridException;
import org.gridgain.grid.GridJob;
import org.gridgain.grid.GridJobResult;
import org.gridgain.grid.GridTaskSplitAdapter;

public class SimulationTask2 extends GridTaskSplitAdapter<ProgramsWithEnvironment, Collection>{
	
	@Override
	protected Collection<? extends GridJob> split(int gridSize, ProgramsWithEnvironment programs) throws GridException {
		return programs.split();
	}

	@Override
	public Collection reduce(List<GridJobResult> results) throws GridException {
		Collection c = new ArrayList();
		for (GridJobResult gridJobResult : results) {
			c.add(gridJobResult.getData());
		}
		return c;
	}

}
